{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([1.0000, 0.9986, 0.9945, 0.9877, 0.9781, 0.9659, 0.9511, 0.9336, 0.9135,\n",
      "        0.8910, 0.8660, 0.8387, 0.8090, 0.7771, 0.7431, 0.7071, 0.6691, 0.6293,\n",
      "        0.5878, 0.5446, 0.5000, 0.4540, 0.4067, 0.3584, 0.3090, 0.2588, 0.2079,\n",
      "        0.1564, 0.1045, 0.0523, 0.0523, 0.0523, 0.1045, 0.1564, 0.2079, 0.2588,\n",
      "        0.3090, 0.3584, 0.4067, 0.4540, 0.5000, 0.5446, 0.5878, 0.6293, 0.6691,\n",
      "        0.7071, 0.7431, 0.7771, 0.8090, 0.8387, 0.8660, 0.8910, 0.9135, 0.9336,\n",
      "        0.9511, 0.9659, 0.9781, 0.9877, 0.9945, 0.9986])\n"
     ]
    }
   ],
   "source": [
    "import torch, torch.nn.functional as F\n",
    "from math import pi\n",
    "\n",
    "onehot_dim = 60\n",
    "\n",
    "temp = torch.arange(0, onehot_dim)\n",
    "std_w = torch.abs(torch.sin(temp * pi / onehot_dim - pi / 2))\n",
    "std_w[onehot_dim // 2] = std_w[onehot_dim // 2 + 1]\n",
    "print(std_w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n        0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,\n        0., 0., 0., 0., 0., 0.])"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "angle_targets = torch.tensor(pi / 4)\n",
    "angle_targets = ((angle_targets + pi / 2) / pi * onehot_dim).long()  # 得到分类角度目标\n",
    "# print(angle_targets.shape, angle_targets, angle_targets.max(),angle_targets.min())\n",
    "# print(angle_pred_prob.shape, angle_targets.shape, angle_weight.shape)\n",
    "# print('*' * 100)\n",
    "# print(\"w uniuqe\", w.unique(), \"\\nangle_targets_unique\", angle_targets.unique())\n",
    "# print(w)\n",
    "angle_target_onehot = F.one_hot(angle_targets, num_classes=onehot_dim).float()\n",
    "angle_target_onehot\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "data": {
      "text/plain": "False"
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "std_w = std_w.to('cuda')\n",
    "torch.stack([torch.roll(std_w,(t-30,)) for t in [angle_targets]*10000],0)[0]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'torch' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "\u001B[0;32m/tmp/ipykernel_14580/21649115.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mtorch\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstack\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mtorch\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mroll\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mstd_w\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mt\u001B[0m\u001B[0;34m-\u001B[0m\u001B[0;36m30\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0mangle_targets\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0;36m160000\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;36m0\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;36m0\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmin\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      2\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mNameError\u001B[0m: name 'torch' is not defined"
     ]
    }
   ],
   "source": [
    "torch.stack([torch.roll(std_w,(t-30,)) for t in [angle_targets]*160000],0)[0].min()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([[0, 1, 2, 3, 4, 5],\n        [0, 1, 2, 3, 4, 5],\n        [0, 1, 2, 3, 4, 5]])"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "a = torch.arange(6)\n",
    "a\n",
    "torch.stack([a,a,a],0)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}